from PAM30 import PAMIE
from  db_result import *
from zqc import extract_result
import zqc
if __name__ == '__main__':
    import sys

    items=[]
    for object in DB_QUERY_DAILY.find({}, 0):
        items.append(object)
#    ie=PAMIE(timeOut=600)
    extractor=extract_fake_zq()
    for item in items:
        try:
            if int(item['code'])==200 and len(item['type'])==0:
                for e in item['type']:
                    type=e['type']
                    if type=='location=myurl':
                        print type
                import os
                import tempfile
                from rarfile import *
                from zipfile import *
                dir=tempfile.mkdtemp(suffix='200',dir='temp')
                zip_file=os.path.join('data',item['zip'])
                ZipFile(zip_file).extractall(path=dir)
                result=extract_result()
                def t(path):
                    for f in os.listdir(path):
                        fbfile=os.path.join(path,f)
                        if os.path.isdir(fbfile):
                            t(fbfile)
                        else:
                            stringU=zqc.unicode_html(open(fbfile,'rb'))
                            sec_company=extractor.gettype(stringU)
                            pass
                try:
#                    t(dir)
                    pass
                except:
                    pass                
        except Exception,ex:
           # print ex
            pass
def xx():
    ONE_SEC=10
    ie=PAMIE(timeOut=ONE_SEC*120)
    ie.navigate("google.com")
    ie.setTextBox('q','python')
    ie.clickButton('btnG')
    print ie.findElement('meta')
    html=ie.outerHTML()
    ie.navigate("baidu.com")
    ie.quit()   
